import comSvc from '@/common/comSvc.js';
import service from './service.js';
import filter from '@/common/filter.js';
import _ from '@/common/lodash.js';
import api from '@/common/api.js'
export default {
	data() {
		return {
			coinImgUrl: api.coinImgUrl,
			statesTex: {
				FAIL: '委托失败',
				WAITING: '委托中...',
				CANCEL: '委托取消',
				SUCCESS: '交易成功',
				PROCESSING: '委托中...',
			},
			acolor: '#000',
			filter,
			optype: 'bone',
			opone: '买一价',
			cexchange: [{
					name: "USDT"
				},
				{
					name: "LKB"
				},
				{
					name: "USDT"
				},
			],
			isPayPwd: '',
			pairs: 'USDT',
			title: '',
			coins: 'USDT',
			symbol: '',
			showSelect: false,
			type: 'BUY',
			sellList: [],
			buyList: [],
			oldSellList: [],
			oldBuyList: [],
			lastSellList: [],
			lastBuyList: [],
			tradeList: [],
			oldTradeList: [],
			startDate: this.GetDateStr(30),
			endDate: this.$formta(new Date(), 'yyyy-MM-dd'),
			entrustList: [],
			coinList: [],
			coinMainList: [],
			symbolType: '',
			sale: '',
			average: 0,
			asset: [],
			money: 0,
			price: '',
			trigger: '',
			number: '',
			isLogin: false,
			numberMaxLength: -1,
			priceMaxLength: -1,
			payPwd: '',
			maxNumber: 0,
			maxPrice: 0,
			pageNo: 1,
			pageSize: 10,
			loading: true,
			noData: false,
			Times: null,
			lastName: 'x',
			panGun: null,
			sellScrollTop: 0,
			buyScrollTop: 0,
			// rangeValues: [2, 5], //当前区间值
			// slideWidth: 350, //宽度
			// slideHeight: 80,  //高度
			// slideBlockSize: 56, //圆形按钮大小
			// slideMin: 0,  //slider最小值
			// slideMax: 12,  //slider最大值
			minValue: 0,
			maxValue: 100,
			rangeValues: [0, 0],
			slideHeight: 80,
			slideWidth: 328,
			slideBlockSize: 45,
			slideMin: 0,
			slideMax: 100,
			showCoin: false,
			coinType: [],
			showGo: false,
			isTab: false,
			step: '0',
			levers: 0,
			leverss: 0,
			// '止盈止损'
			entrustLists: ['限价委托'],
			leverLists: ['5X', '10X', '15X', '20X'],
			btnList: ['调整杠杆', '调整保证金', '平仓'],
			inde: 0,
			isFlat: false,
			width: 0,
			left: '0',
			mleft: '0',
			bcolor0: '',
			bcolor25: '',
			bcolor50: '',
			bcolor75: '',
			bcolor100: '',
			isCoin: false,
			entrust: 'new',
			deep: 0,
			deepList: [],
			entrusts: '限价委托',
			ssCoin: '',
			isLoss: false,
			isLossno: false,
			next: "true",
			configList: [],
			PRICEPRECISION: 4,
			AMOUNTPRECISION: 4,
			leng: 0,
			priceList:[],
		};

	},
	watch: {
		number(newVal, oldVal) {
			if (newVal) {
				if (parseFloat(newVal) > parseFloat(this.maxNumber)) {
					this.number = filter.fix(this.maxNumber, this.AMOUNTPRECISION);
				} else {
					this.leng = newVal / this.maxNumber * 100;
				}
			}

		},
		price(newVal) {
			if (newVal && newVal != 0) {
				this.maxNumber = filter.fix(this.money / (this.price ? this.price : 0) * 1, 6);
			} else {
				this.maxNumber = 0;
			}
		},
		pairs(val) {
			this.coinList = this.formatData(this.coinMainList)
		}
	},
	//卸载轮训
	onUnload() {
		clearTimeout(this.Times)
		this.$store.commit('setIsPan', false);
	},
	//卸载轮训
	// onHide() {
	// 	clearTimeout(this.Times)
	// 	this.$store.commit('setIsPan', false);
	// },
	created() {
		if (uni.getStorageSync('tradeType')) {
			this.type = uni.getStorageSync('tradeType');
		}
		this.backType();
		this.$store.commit('setIsPan', true);
		Promise.all([service.getConfigSymbolRank(), comSvc.getTrade(), service.symbolConfigList()])
			.then(data => {
				this.loading = false;
				if (data[0].data.code == '100200') {
					this.coinMainList = data[0].data.data;
					this.priceList = data[1].data;
					this.configList = data[2].data.data;
					let innerObj;
					for (let key in this.coinMainList) {
						for (let i = 0; i < this.configList.length; i++) {
							innerObj = this.configList[i];
							if (this.coinMainList[key].symbol === innerObj.symbol) {
								this.coinMainList[key][innerObj.profileKey] = innerObj.profileValue;
							}
						}
					}
					// this.getPan();
					// this.getPanInfo();
					this.loopPan();
					this.coinList = this.formatTrade(this.formatData(this.coinMainList));
					if (uni.getStorageSync('type')) {
						this.symbol = uni.getStorageSync('type');
						this.title = uni.getStorageSync('title');
						this.pairs = uni.getStorageSync('coin');
						this.coins = uni.getStorageSync('coin');
						this.symbolType = uni.getStorageSync('symbol');
						this.PRICEPRECISION = uni.getStorageSync('PRICEPRECISION');
						this.AMOUNTPRECISION = uni.getStorageSync('AMOUNTPRECISION');
					} else {
						this.symbol = this.coinList[0].assetCode2;
						this.title = this.coinList[0].title;
						this.pairs = this.coinList[0].assetCode1;
						this.coins = this.coinList[0].assetCode1;
						this.symbolType = this.coinList[0].symbol;
						this.PRICEPRECISION = this.coinList[0].PRICEPRECISION;
						this.AMOUNTPRECISION = this.coinList[0].AMOUNTPRECISION;
						uni.setStorageSync('symbol', this.coinList[0].symbol);
						uni.setStorageSync('title', this.coinList[0].title);
						uni.setStorageSync('coin', this.coinList[0].assetCode1);
						uni.setStorageSync('type', this.coinList[0].assetCode2);
						uni.setStorageSync('PRICEPRECISION', this.coinList[0].PRICEPRECISION);
						uni.setStorageSync('AMOUNTPRECISION', this.coinList[0].AMOUNTPRECISION);
					}
					this.deepList = [];
					let deep = filter.fix(Math.pow(0.1, this.PRICEPRECISION), this.PRICEPRECISION)
					for (let i = 0; i <= this.PRICEPRECISION; i++) {
						this.deepList.push(deep * (Math.pow(10, i)))
					}
					this.entrustList = [];
					this.getEntrust();
				} else {
					this.errors(data[0].data.msg);
				}
			})
			.catch(err => {
				this.loading = false;
			});
	},
	onShow() {
		if (this.$api.isLogin()) {
			this.isLogin = true;
			this.getAsset();
		} else {
			if (this.type == 'CURRENT' || this.type == 'HISTORY') {
				this.$api.goLogin('../login/login');
			}
			this.isLogin = false;
		}
	},
	methods: {
		//显示币列表
		coinShow() {
			this.showCoin = true;
		},
		//设置百分比
		sliderChange(e) {
			this.number = filter.floorFix((filter.floorFix(this.maxNumber, this.AMOUNTPRECISION) * (e.detail.value / 100)), this
				.AMOUNTPRECISION);
		},
		showSel() {
			this.isCoin = true;
		},
		closes(name) {
			this[name] = false;
		},
		selCoin(name) {
			this.entrusts = name;
			this.isCoin = false;
			if (uni.getStorageSync('next')) {
				this.next = uni.getStorageSync('next');
			}
			if (name == '止盈止损' && this.next == 'true') {
				this.isLoss = true;
			}
		},
		tradeCompose(curArr, oldArr) {
			let cur = curArr;
			let old = oldArr;
			if (!old.length) {
				this.tradeList = cur;
				return cur;
			}
			let resArr = [];

			for (var i = 0; i < cur.length; i++) {
				let n = 0;
				let curItem = cur[i];
				for (var j = 0; j < old.length; j++) {
					let oldItem = old[j];
					if (curItem.num === oldItem.num && curItem.price === oldItem.price && curItem.time === oldItem.time && curItem.type ===
						oldItem.type) {
						continue;
					} else {
						n += 1;
					}
				}
				if (n === (old.length)) {
					curItem.isAdd = true;
					curItem.isAnimated = false;
					resArr.push(curItem);
				}
			}

			setTimeout(() => {
				resArr.forEach((item, index) => {
					item.isAnimated = true;
				});
			}, 1000);

			let returnArr = resArr.concat(old);

			this.tradeList = resArr.concat(this.tradeList);


			if (this.tradeList.length > 200) {
				this.tradeList = this.tradeList.slice(0, 100);
			}
			// console.log(JSON.stringify(returnArr),'================================================');

			return returnArr;

		},
		//下次不再提示
		nextNo() {
			this.isLossno = !this.isLossno;
		},
		know(name) {
			this[name] = false;
			if (this.isLossno == true) {
				uni.setStorageSync("next", "false")
			}
		},
		//设置深度
		setDeep(e) {
			this.deep = e.target.value;
			let deepLen;
			if (this.deepList[this.deep].toString().split('.')[1]) {
				deepLen = this.deepList[this.deep].toString().split('.')[1].length;
			} else {
				deepLen = 0;
			}
			this.PRICEPRECISION = deepLen;
			this.getPan(deepLen)

		},
		//轮盘查询
		loopPan() {
			if (!this.PAN) {
				clearTimeout(this.Times)
				return false;
			}
			this.getPan();
			this.getPanInfo();
			this.Times = setTimeout(() => {
				this.loopPan();
			}, 2000)
		},
		//调整杠杠
		showlever(indexs) {
			this.inde = indexs;
			if (indexs == 0) {
				this.$goPage("lever/lever")
			}
			if (indexs == 1) {
				this.$goPage("ensure/ensure")
			}
			if (indexs == 2) {
				this.isFlat = true;
			}
		},
		//选择1
		set1(e) {
			this.levers = e.target.value;
		},
		//选择2
		set2(e) {
			this.leverss = e.target.value;
		},
		//前往K线
		goKline(symbolType) {
			this.$goPage(
				`../exchange/kline/kline?type=${this.symbolType}&title=${this.title}&coin=${this.coins}&symbol=${this.symbol}&PRICEPRECISION=${this.PRICEPRECISION}&AMOUNTPRECISION=${this.AMOUNTPRECISION}`
			);
		},
		//重新更改页面
		goPage(url) {
			uni.redirectTo({
				url: url
			})
		},
		//减
		reduce(name) {
			if (this[name] >= 1) {
				this[name] = Number(this[name]) - 1;
			} else if (this[name] < 1 && this[name] >= 0) {
				this[name] = 0;
			} else {
				this[name] = 0;
			}
		},
		//加
		add(name) {
			if (this[name] >= 0) {
				this[name] = Number(this[name]) + 1
			} else {
				this[name] = 0;
			}
		},
		//重新更改页面
		goSwitch(symbol, title, coin, type, price, amout) {
			uni.setStorageSync('symbol', symbol);
			uni.setStorageSync('title', title);
			uni.setStorageSync('coin', coin);
			uni.setStorageSync('type', type);
			uni.setStorageSync('PRICEPRECISION', price);
			uni.setStorageSync('AMOUNTPRECISION', amout);
			this.PRICEPRECISION = price;
			this.AMOUNTPRECISION = amout;
			this.showCoin = false;
			this.symbol = type;
			this.title = title;
			this.pairs = coin;
			this.coins = coin;
			this.symbolType = symbol;
			this.deepList = [];
			let deep = filter.fix(Math.pow(0.1, this.PRICEPRECISION), this.PRICEPRECISION)
			for (let i = 0; i <= this.PRICEPRECISION; i++) {
				this.deepList.push(deep * (Math.pow(10, i)))
			}
			this.deep = 0;
			this.tradeList = [];
			this.getPanInfo();
			this.entrustList = [];
			this.getEntrust();
		},
		//跳转
		goTo(url) {
			this.showGo = false;
			this.$goPage(url)
		},
		//设置要查询的交易对
		setCoin(name) {
			this.pairs = name;
		},
		//格式化数据
		formatData(data) {
			let arr = [];
			data.map((e, i) => {
				if (e.status !== "INIT" && e.status !== "DELISTED") {
					arr.push(e);
				}
			})
			return arr;
		},
		//格式化币种交易数据
		formatTrade(data) {
			data.map((e, index) => {
				for (let i in this.priceList) {
					if (e.symbol == i) {
						e.trade = this.priceList[i];
						let pr_ne = this.priceList[i].newPrice ? this.priceList[i]['newPrice'] * 1 : 0; // 最新價
						let pr_op = this.priceList[i].newPrice ? this.priceList[i]['24Price'] * 1 : 0; // 開盤價
						// 漲跌幅

						let distance = pr_ne - pr_op;
						let symbol = '';
						if (distance < 0) {
							symbol = '-';
						} else if (distance > 0) {
							symbol = '+';
						}
						if ((this.priceList[i].newPrice ? this.priceList[i]['24Price'] * 1 : 0) == 0) {
							e.trade.changeRatio = filter.floorFix(0, 2);
						} else {
							e.trade.changeRatio = symbol + filter.floorFix((filter.abs(distance) / pr_op) * 100, 2);
						}
						e.trade.changeRatioNum = parseFloat(e.trade.newPrice ? e.trade.changeRatio : 0);
					}
				}
			});
			return data;
		},
		//取消委托
		cancelOrder(item) {
			let that = this;
			uni.showModal({
				title: '提示',
				content: '是否取消当前委托挂单',
				success(res) {
					if (res.confirm) {
						service
							.cancelOrder({
								symbol: that.symbolType,
								orderNo: item.payTransactionNo
							})
							.then(({
								data
							}) => {
								if (data.code == '100200') {
									that.pageNo = 1;
									that.entrustList = [];
									that.getEntrust();
									that.HMmessages.show('撤单成功', {
										textAlign: 'center',
										background: '#356e36',
										fontColor: '#fff'
									});
								} else {
									that.errors(data.msg);
								}
							});
					}
				}
			});
		},
		//获取委托
		getEntrust() {
			this.loading = true;
			let name = this.entrust == 'now' ? 'current' : 'history';
			service[name]({
				symbol: this.symbolType,
				pageNo: this.pageNo,
				pageSize: this.pageSize,
				beginTime: this.startDate,
				endTime: this.endDate
			}).then(({
				data
			}) => {
				this.loading = false;
				if (data.code == '100200') {
					data.data.list.map((e, i) => {
						e.coin = e.symbol.split('_')[1];
					})
					this.entrustList = this.entrustList.concat(data.data.list);
					if (data.data.pageNum == 1 || data.data.pageNum == 0) {
						this.noData = true;
						return false;
					}
					if (this.pageNo >= data.data.pageNum) {
						this.noData = true;
					} else {
						this.noData = false;
					}
				} else {
					this.pageNo--;
					this.errors(data.msg);
				}
			});
		},
		//加载更多
		load() {
			if (this.loading) {
				return false;
			}
			if (this.noData) {
				return false;
			}
			this.pageNo++;
			this.loading = true;
			this.getEntrust();
		},
		//获取时间
		GetDateStr(AddDayCount) {
			var dd = new Date();
			dd.setDate(dd.getDate() - AddDayCount); //获取AddDayCount天前的日期
			var y = dd.getFullYear();
			var m = dd.getMonth() + 1; //获取当前月份的日期
			var d = String(dd.getDate()).length < 2 ? '0' + dd.getDate() + '' : dd.getDate();
			// var d = dd.getDate();
			return y + '-' + (Number(m + '') < 10 ? '0' + m : m) + '-' + d;
		},
		//买入卖出
		buySell(type, bool) {
			let that = this;
			if (!this.veif()) {
				return false;
			}
			if (!bool) {
				if (this.USERINFO.authLevel == 'LEVEL0') {
					uni.showModal({
						title: '提示',
						content: '请进行实名认证后进行购买',
						confirmText: '前往实名',
						success(res) {
							if (res.confirm) {
								that.$goPage('../authentication/authentication');
							}
						}
					});
					return false;
				}
				if (!this.USERINFO.setPayPassword) {
					uni.showModal({
						title: '提示',
						content: '请先设置资金密码在进行交易',
						confirmText: '前往设置',
						success(res) {
							if (res.confirm) {
								that.$goPage('../account/securitySetting/securitySetting');
							}
						}
					});
					return false;
				}
			}
			if (this.AVOID == 0 && !bool) {
				this.isPayPwd = type;
				return false;
			}
			let params = {
				price: this.price,
				amount: this.number,
				tradeCoinType: type,
				tradeCoinFlag: 'FIXED',
				orderNo: this.$api.outOrder(),
				symbol: this.symbolType
			};
			let header = {
				'pay-password': this.AVOID == 1 ? '%20' : this.payPwd
			};
			this.$api.showLoading();
			service.createdOrder(params, header).then(({
				data
			}) => {
				this.$api.hideLoading();
				if (data.code == '100200') {
					that.price = '';
					that.number = '';
					that.closeModal('isPayPwd');
					that.getAsset();

					uni.showToast({
						icon: 'none',
						title: '挂单成功',
						position: 'center'
					})
				} else {
					uni.showToast({
						icon: 'none',
						title: data.msg,
						position: 'center'
					})
				}
			});
		},
		//设置百分比
		// percentage(number) {
		// 	if (this.type == 'BUY') {
		// 		if (number == 100) {
		// 			this.number = this.maxNumber
		// 		} else {
		// 			this.number = filter.fix(this.maxNumber * (number / 100));
		// 		}
		// 	} else {
		// 		if (number == 100) {
		// 			this.number = this.money
		// 		} else {
		// 			this.number = filter.fix(this.money * (number / 100));
		// 		}
		// 	}
		// },
		//设置小数点位数长度
		setMaxLength(name, val, maxName) {
			let precision = 6;
			let arrs = val.split('.');
			let attr0 = arrs[0];
			let attr1 = arrs[1];
			if (attr1) {
				this[name] = attr0 + '.' + attr1.slice(0, precision);
				this[maxName] = attr1.slice(0, precision).length == 6 ? this[name].length : -1;
			} else {
				this[maxName] = -1;
			}
		},
		//点击设置价格
		setPrice(number) {
			this.price = filter.fix(number, this.PRICEPRECISION);
		},
		//获取用户资产
		getAsset() {
			comSvc.getAssets().then(({
				data
			}) => {
				if (data.code == '100200') {
					this.asset = data.data;
					this.asset.map((e, i) => {
						let coin = this.type == 'BUY' ? this.coins : this.symbol;
						if (e.assetCode == coin) {
							this.money = e.amountAvailable;
						}
					});
				} else {
					this.errors(data.msg);
				}
			});
		},
		//获取买卖盘成交记录
		getPanInfo() {
			comSvc
				.getPanInfo({
					symbol: this.symbolType
				})
				.then(({
					data
				}) => {
					this.average = data.order ? data.order[0].price : 0;
					this.oldTradeList = this.tradeList;
					let orderList = data.order || [];
					this.tradeCompose(orderList, this.oldTradeList);
				});
		},
		compose(cur, old, type, cbfn) {
			let curArr = cur.concat([]);
			let oldArr = old.concat([]);
			curArr.forEach((item) => {
				item.isDel = false;
				item.isAdd = false;
				item.isUpdate = false;
			});

			oldArr.forEach((item) => {
				item.isDel = false;
				item.isAdd = false;
				item.isUpdate = false;
			});

			let mergeArr = []; // 用于显示的
			cbfn && cbfn(curArr)

			if (!old.length) {
				return curArr;
			}



			if (type === 'buy') {
				let i = 0;
				let j = 0;
				while (i < oldArr.length || j < curArr.length) {
					if (!oldArr[i]) {
						curArr[j].isAdd = true;
						mergeArr.push(curArr[j]);
						j += 1;

					} else if (!curArr[j]) {
						oldArr[i].isDel = true;
						mergeArr.push(oldArr[i]);
						i += 1;
					} else if (oldArr[i].price == curArr[j].price && oldArr[i].count == curArr[j].count) {
						mergeArr.push(curArr[j]);
						i += 1;
						j += 1;

						// 新旧数据 价格相同 数量不同  更新操作
					} else if (oldArr[i].price == curArr[j].price && oldArr[i].count != curArr[j].count) {
						curArr[j].isUpdate = true;
						mergeArr.push(curArr[j]);

						i += 1;
						j += 1;

						// 旧数据 比 新数据 价格低 
					} else if (oldArr[i].price < curArr[j].price) {
						curArr[j].isAdd = true;
						mergeArr.push(curArr[j]);
						j += 1;
						// 旧 比  新  高
					} else if (oldArr[i].price > curArr[j].price) {
						oldArr[i].isDel = true;
						mergeArr.push(oldArr[i]);
						i += 1;
					}else {
						console.log('1')
					}
				}
			} else if (type === 'sell') {
				let i = 0;
				let j = 0;
				while (i < oldArr.length || j < curArr.length) {
					if (!oldArr[i]) {
						curArr[j].isAdd = true;
						mergeArr.push(curArr[j]);
						j += 1;

					} else if (!curArr[j]) {

						oldArr[i].isDel = true;
						mergeArr.push(oldArr[i]);
						i += 1;

					} else if (oldArr[i].price == curArr[j].price && oldArr[i].count == curArr[j].count) {
						mergeArr.push(curArr[j]);
						i += 1;
						j += 1;

						// 新旧数据 价格相同 数量不同  更新操作
					} else if (oldArr[i].price == curArr[j].price && oldArr[i].count != curArr[j].count) {
						curArr[j].isUpdate = true;
						mergeArr.push(curArr[j]);

						i += 1;
						j += 1;

						// 旧数据 比 新数据 价格低 

					} else if (oldArr[i].price > curArr[j].price) {

						curArr[j].isAdd = true;
						mergeArr.push(curArr[j]);
						j += 1;
						// 旧 比  新  高
					} else if (oldArr[i].price < curArr[j].price) {

						oldArr[i].isDel = true;
						mergeArr.push(oldArr[i]);
						i += 1;
					} else {
						console.log('1')
					}

				}
				// log(mergeArr);
			}
			return mergeArr;
		},
		//获取买卖盘数据
		getPan(deepLen) {
			this.panGun && clearInterval(this.panGun)
			comSvc
				.getBuySell({
					symbol: this.symbolType
				})
				.then(({
					data
				}) => {
					if (data.sell && data.sell === '[]') {
						this.sellList = [];
					}
					if (data.buy && data.buy === '[]') {
						this.buyList = [];
					}
					this.oldSellList = this.sellList;
					this.oldBuyList = this.buyList;
					let sellLists = typeof data.sell == 'string' ? [] : this.forData(data.sell);
					let buyLists = typeof data.buy == 'string' ? [] : this.forData(data.buy);
					this.lastBuyList = this.compose(buyLists, this.oldBuyList, 'buy', (curArr) => {
						this.buyList = curArr;
					});
					this.lastSellList = this.compose(sellLists, this.oldSellList, 'sell', (curArr) => {
						this.sellList = curArr;
					});
					setTimeout(() => {
						this.lastBuyList.forEach((item, index) => {
							item.isAdd = false;
						});
						this.lastSellList.forEach((item, index) => {
							item.isAdd = false;
						});
					}, 800)
				});
		},
		forData(prevArr) {
			if (!prevArr[0]) {
				return [0];
			}
			let max = _.maxBy(prevArr, 1)[1];
			let newArr_obj = [];
			let pre = this.PRICEPRECISION;
			for (let i = 0; i < prevArr.length; i++) {
				let width = prevArr[i][1] / max * 100 + '%';
				let cou = prevArr[i][1];
				for (let j = i + 1; j < prevArr.length; j++) {
					if (filter.floorFix(prevArr[i][0], pre) == filter.floorFix(prevArr[j][0], pre)) {
						cou += parseFloat(prevArr[j][1]);
						i++;
						j = i;
					}
				}
				newArr_obj.push({
					price: filter.floorFix(prevArr[i][0], pre),
					count: cou == 0 ? prevArr[i][1] : cou,
					width,
					isAdd: false,
					isDel: false,
					isUpdate: false
				})
			}
			// if (newArr_obj.length > 10) {
			// 	newArr_obj = newArr_obj.slice(0, 10);
			// }
			return newArr_obj;
		},

		//隐藏币种选择
		hidePopup() {
			this.isFlat = false;
		},
		//修改手机返回
		back() {
			let that = this;
			this.Times && clearInterval(that.Times);
			setTimeout(() => {
				clearInterval(that.Times)
			}, 500)
			let length = getCurrentPages();
			if (length.length == 1) {
				uni.switchTab({
					url: '../index/index'
				});
			} else {
				uni.navigateBack();
			}
		},
		//设置时间
		bindDateChange(e, name) {
			this[name] = e.target.value;
			this.pageNo = 1;
			this.entrustList = [];
			this.getEntrust();
		},
		//返回类型
		backType() {
			if (this.sale) {
				let name = this.sale;
				this.type = name;
				if (name == 'BUY' || name == 'SELL') {
					this.$store.commit('setIsPan', true);
					this.loopPan();
					this.asset.map((e, i) => {
						let coin = name == 'BUY' ? this.coins : this.symbol;
						if (e.assetCode == coin) {
							this.money = e.amountAvailable;
						}
					});
				} else {
					this.$store.commit('setIsPan', false);
					this.pageNo = 1;
					this.entrustList = [];
					this.getEntrust();
				}
			}
		},
		//设置
		setOpen(name) {
			this.mnull = name;
		},
		//委托
		enType(name) {
			this.entrust = name;
			this.$store.commit('setIsPan', false);
			this.pageNo = 1;
			this.entrustList = [];
			this.getEntrust();
		},
		//价格设置
		opType(name) {
			this.optype = name;
			if (name == 'opponent') {
				this.opone = '对手价';
			}
			if (name == 'bone') {
				this.opone = '买一价';
			}
			if (name == 'sone') {
				this.opone = '卖一价';
			}
		},
		//设置类型
		setType(name) {
			this.type = name;
			uni.setStorageSync('tradeType', name);
			if (name == 'BUY' || name == 'SELL') {
				this.$store.commit('setIsPan', true);
				this.loopPan();
				this.asset.map((e, i) => {
					let coin = name == 'BUY' ? this.coins : this.symbol;
					if (e.assetCode == coin) {
						this.money = e.amountAvailable;
					}
				});
			} else {
				this.$store.commit('setIsPan', false);
				this.pageNo = 1;
				this.entrustList = [];
				this.getEntrust();
			}
		},
		//错误提示
		errors(text) {
			this.HMmessages.show(text, {
				textAlign: 'center',
				background: '#74272d',
				fontColor: '#fff'
			});
		},
		//验证
		veif() {
			if (!this.price || !Number(this.price)) {
				uni.showToast({
					icon: 'none',
					title: '请输入正确的价格',
					position: 'center'
				})
				return false;
			}
			if (!this.number || !Number(this.number)) {
				uni.showToast({
					icon: 'none',
					title: '请输入正确的数量',
					position: 'center'
				})
				return false;
			}
			return true;
		},
		//隐藏弹窗
		closeModal(name) {
			this[name] = '';
			this.payPwd = '';
		}
	}
}
